begintownscript;

variables;
short bmessage,pcs,leadchar,others_ok,twondx,armor_cool,rest_need,abil_no;
short sp_no;
string custom_m;

body;

beginstate INIT_STATE;

	set_char_dialogue_pic(6,531,0);

	if(get_flag(45,0) < 5){
		set_total_visibility(0);
		force_view_center(9,8);
		march_party(4,25);
		march_party(4,25);
		march_party(4,25);
		march_party(4,25);
		force_instant_terrain_redraw();
		pause(3);

		reset_dialog();
		if(party_size() == 1){
			add_dialog_str(0,"What's happening?  This vertigo, this unexplainable nausea...  It's as if my head is being thrown into my stomach and my stomach is being thrown up my throat!",0);
			add_dialog_str(1,"Eventually, I begin to feel somewhat more stable.  Reality begins to coalesce around me again, and I am able to regain some stable footing as I step out of the nothingness and onto a cold, hard floor somewhere bright and new.",0);
		}
		if(party_size() > 1){
			add_dialog_str(0,"What's happening?  This vertigo, this unexplainable nausea...  It's as if our heads are being thrown into our stomachs and our stomachs are being thrown up our throats!",0);
			add_dialog_str(1,"Eventually, we begin to feel somewhat more stable.  Reality begins to coalesce around us again, and we are able to regain some stable footing as we step out of the nothingness and onto a cold, hard floor somewhere bright and new.",0);
		}
		add_dialog_choice(0,"Woah.");
		bmessage = run_dialog(1);

		march_party(9,8);
		set_character_facing(1000,6);
		put_boom_on_space(9,8,7,0);
		force_instant_terrain_redraw();
		run_animation_sound(43);
		pause(3);

		if(party_size() > 1){
			march_party(10,8);
			force_view_center(10,8);
			put_boom_on_space(9,8,7,0);
			force_instant_terrain_redraw();
			run_animation_sound(43);
			pause(3);
		}

		if(party_size() > 2){
			march_party(11,8);
			force_view_center(11,8);
			put_boom_on_space(9,8,7,0);
			force_instant_terrain_redraw();
			run_animation_sound(43);
			pause(3);
		}

		if(party_size() == 4){
			march_party(12,8);
			force_view_center(12,8);
			put_boom_on_space(9,8,7,0);
			force_instant_terrain_redraw();
			run_animation_sound(43);
			pause(3);
		}

		block_entry(1);
		set_flag(45,0,5);

		reset_dialog();
		if(party_size() == 1)
			add_dialog_str(0,"Now...  where am I?",0);
		if(party_size() > 1)
			add_dialog_str(0,"Now...  where are we?",0);
		add_dialog_choice(0,"...");
		bmessage = run_dialog(0);
	}

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

	if(char_ok(7) == TRUE)
		set_character_pose(7,14);

break;

beginstate 10;

	if(get_flag(45,0) == 5){
		if(is_combat() == TRUE){
			block_entry(1);
			end();
		}
		large_draw_pic_dialog(530,"Well.  Here he is.");
		reset_dialog();
		add_dialog_str(0,"Honestly, for a mage capable of making a tele-porter device, he doesn't look particularly outlandish.  Even though the walls of his home are made of basalt, it's still very simply designed.",0);
		if(party_size() == 1)
			add_dialog_str(1,"The man turns his head towards me.  He looks me up and down with his eyes stretched open wide and his mouth curling into a light smile.  Is he appraising my skill?",0);
		else
			add_dialog_str(1,"The man turns his head towards us.  He looks us up and down with his eyes stretched open wide and his mouth curling into a light smile.  Is he appraising our skill?",0);
		clear_buffer();
		append_string("_It is nice for you to finally make it, ");
		pcs = 0;
		while(pcs <= 3){
			if(char_ok(pcs) == TRUE){
				others_ok = (pcs + 1);
				twondx = 0;
				while(others_ok < 4 && twondx < 2){
					if(char_ok(others_ok) == 1){
						twondx = (twondx + 1);
					}
					others_ok = (others_ok + 1);
				}
				if(twondx == 1){
					append_char_name(pcs);
					append_string(" and ");
				}
				if(twondx > 1){
					append_char_name(pcs);
					append_string(", ");
				}
				if(twondx == 0){
					append_char_name(pcs);
				}
			}
			pcs = (pcs + 1);
		}
		append_string(".  ");
		if(party_size() > 2)
			append_string("All of you, ");
		if(party_size() == 2)
			append_string("Both of you, ");
		append_string("I really do appreciate it.  As you might have guessed, I am the one who summoned you here._");
		get_buffer_text(custom_m);
		add_dialog_str(2,custom_m,0);
		add_dialog_str(3,"_But none of this answers what questions you have, and what questions I want to answer for you.  Come, let us talk._",0);
		bmessage = run_dialog(1);
		toggle_quest(1,0);
		award_party_xp(250,25);

		set_flag(45,0,6);
	}

break;

beginstate 11;

	if((get_flag(65,0) == 5) && (get_flag(70,0) == 0)){
		if(get_flag(24,1) == 0)
			message_dialog("...where the hell did the mysterious figure go?","_Hey!  I'm over here._  It came from the southeast.");
		else
			message_dialog("...where the hell did _K_ go?","_Hey!  I'm over here._  It came from the southeast.");
		set_flag(70,0,1);
	}

break;

beginstate 12;

	if(get_flag(65,0) == 5){
		armor_cool = 0;

		march_party(21,22);
		force_view_center(21,22);
		force_instant_terrain_redraw();
		play_sound(49);
		pause(2);

		while(armor_cool == 0){
			reset_dialog();
			add_dialog_str(0,"_Ah, so you found me.  Good.  I have decided to give you a magical suit of armor to protect yourself from the brigands, but I want to make sure that I make something which suits your needs._",0);
			add_dialog_str(1,"_So tell me:  Do you want this suit of armor to be used by a melee fighter, a ranged fighter or a magician?_",0);
			add_dialog_choice(0,"Melee Fighter");
			add_dialog_choice(1,"Ranged Fighter");
			add_dialog_choice(2,"Magician");
			bmessage = run_dialog(0);
			set_flag(68,0,(bmessage - 1));

			reset_dialog();
			add_dialog_str(0,"_Next, do you want this suit of armor to be heavy or light?  If it's heavy, the protection will be considerable, but it may also interfere with your ability to perform in combat situations._",0);
			add_dialog_choice(0,"Heavy");
			add_dialog_choice(1,"Light");
			bmessage = run_dialog(0);
			set_flag(67,0,(bmessage - 1));

			reset_dialog();
			add_dialog_str(0,"_Finally, do you want armor that will protect you against the elements, or one that will protect you against having your status in combat negatively effected?_",0);
			add_dialog_choice(0,"Elemental protection");
			add_dialog_choice(1,"Status protection");
			bmessage = run_dialog(0);
			set_flag(69,0,(bmessage - 1));

			clear_buffer();
			append_string("_So, you want a ");
			if(get_flag(67,0) == 0)
				append_string("heavy");
			if(get_flag(67,0) == 1)
				append_string("light");
			append_string(" suit of armor for a ");
			if(get_flag(68,0) == 0)
				append_string("melee combatant");
			if(get_flag(68,0) == 1)
				append_string("ranged combatant");
			if(get_flag(68,0) == 2)
				append_string("spellcaster");
			append_string(" that will grant protection from ");
			if(get_flag(69,0) == 0)
				append_string("the elements?_");
			if(get_flag(69,0) == 1)
				append_string("negative status effects?_");
			get_buffer_text(custom_m);
			reset_dialog();
			add_dialog_str(0,custom_m,0);
			add_dialog_choice(0,"No, that's not quite right...");
			add_dialog_choice(1,"Yes.");
			bmessage = run_dialog(0);
			if(bmessage == 1){
				message_dialog("_Okay, no problem.  We'll try this again..._","");
			}
			else{
				message_dialog("_Very well.  Then, stand back and watch magic happen..._","");

				set_character_facing(6,0);
				force_instant_terrain_redraw();
				pause(1);

				set_character_facing(6,6);
				force_instant_terrain_redraw();
				pause(1);

				set_character_pose(6,1);
				set_terrain(21,20,267);
				set_terrain(24,20,267);
				set_terrain(21,24,267);
				set_terrain(24,24,267);
				put_effect_on_space(21,20,10,1,1);
				put_effect_on_space(24,20,10,1,1);
				put_effect_on_space(21,24,10,1,1);
				put_effect_on_space(24,24,10,1,1);
				force_instant_terrain_redraw();
				run_animation_sound(25);
				pause(4);

				if(get_flag(68,0) == 0)
					put_item_on_spot(24,22,59);
				if(get_flag(68,0) == 1)
					put_item_on_spot(24,22,92);
				if(get_flag(68,0) == 2)
					put_item_on_spot(24,22,288);
				put_boom_on_space(24,22,2,0);
				force_instant_terrain_redraw();
				run_animation_sound(10);
				pause(4);

				move_item_on_spot(24,22,-1,-1);
				if((get_flag(68,0) == 0) && (get_flag(67,0) == 0))
					put_item_on_spot(24,22,39);
				if((get_flag(68,0) == 0) && (get_flag(67,0) == 1))
					put_item_on_spot(24,22,34);
				if((get_flag(68,0) == 1) && (get_flag(67,0) == 0))
					put_item_on_spot(24,22,34);
				if((get_flag(68,0) == 1) && (get_flag(67,0) == 1))
					put_item_on_spot(24,22,24);
				if((get_flag(68,0) == 2) && (get_flag(67,0) == 0))
					put_item_on_spot(24,22,24);
				if((get_flag(68,0) == 2) && (get_flag(67,0) == 1))
					put_item_on_spot(24,22,22);
				put_boom_on_space(24,22,3,0);
				force_instant_terrain_redraw();
				run_animation_sound(43);
				pause(6);

				move_item_on_spot(24,22,-1,-1);
				set_terrain(21,20,266);
				set_terrain(24,20,266);
				set_terrain(21,24,266);
				set_terrain(24,24,266);
				put_effect_on_space(21,20,10,4,1);
				put_effect_on_space(24,20,10,4,1);
				put_effect_on_space(21,24,10,4,1);
				put_effect_on_space(24,24,10,4,1);
				if(get_flag(67,0) == 0){
					if(get_flag(68,0) == 0){
						if(get_flag(69,0) == 0)
put_item_on_spot(24,22,485);
						if(get_flag(69,0) == 1)
put_item_on_spot(24,22,486);
					}
					if(get_flag(68,0) == 1){
						if(get_flag(69,0) == 0)
put_item_on_spot(24,22,487);
						if(get_flag(69,0) == 1)
put_item_on_spot(24,22,488);
					}
					if(get_flag(68,0) == 2){
						if(get_flag(69,0) == 0)
put_item_on_spot(24,22,489);
						if(get_flag(69,0) == 1)
put_item_on_spot(24,22,490);
					}
				}
				if(get_flag(67,0) == 1){
					if(get_flag(68,0) == 0){
						if(get_flag(69,0) == 0)
put_item_on_spot(24,22,491);
						if(get_flag(69,0) == 1)
put_item_on_spot(24,22,492);
					}
					if(get_flag(68,0) == 1){
						if(get_flag(69,0) == 0)
put_item_on_spot(24,22,493);
						if(get_flag(69,0) == 1)
put_item_on_spot(24,22,494);
					}
					if(get_flag(68,0) == 2){
						if(get_flag(69,0) == 0)
put_item_on_spot(24,22,459);
						if(get_flag(69,0) == 1)
put_item_on_spot(24,22,460);
					}
				}
				put_effect_on_space(24,22,5,8,2);
				set_character_pose(6,0);
				force_instant_terrain_redraw();
				run_animation_sound(95);
				pause(4);

				set_character_facing(6,4);
				force_instant_terrain_redraw();
				pause(1);

				set_character_facing(6,2);
				force_instant_terrain_redraw();
				pause(1);

				reset_dialog();
				add_dialog_str(0,"_There.  I have made you a suit of armor.  Use it well.  I will be back at the table where I was previously.  We still have much to discuss._",0);
				add_dialog_choice(0,"Thank you.");
				bmessage = run_dialog(1);

				relocate_character(6,17,8);
				set_character_facing(6,4);
				put_boom_on_space(23,22,2,0);
				force_instant_terrain_redraw();
				run_animation_sound(10);
				pause(3);
				block_entry(1);

				set_flag(65,0,6);
				armor_cool = 1;
			}
		}
	}

break;

beginstate 13;

	rest_need = 0;
	pcs = 0;
	while((pcs <= 3) || (rest_need == 0)){
		if(char_ok(pcs) == TRUE){
			if(get_health(pcs) < get_max_health(pcs))
				rest_need = 1;
			if(get_energy(pcs) < (3 * (get_stat(pcs,2) + get_stat(pcs,11) + get_stat(pcs,12))))
				rest_need = 1;
		}
		pcs = (pcs + 1);
	}
	if(rest_need == 0)
		end();
	reset_dialog();
	if(party_size() == 1)
		add_dialog_str(0,"There are beds here.  I could take a rest if I needed to...",0);
	else
		add_dialog_str(0,"There are beds here.  We could take a rest if we needed to...",0);
	add_dialog_choice(0,"Sure.");
	add_dialog_choice(1,"Nope.");
	bmessage = run_dialog(0);
	if(bmessage == 2)
		end();
	change_char_energy(1000,1000);
	change_char_health(1000,1000);
	set_ticks_forward(1350);
	leadchar = 0;
	while(char_ok(leadchar) == FALSE){
		leadchar = (leadchar + 1);
	}
	if(char_loc_x(leadchar) > 7)
		teleport_party(10,16,1);
	else
		teleport_party(4,16,1);

break;

beginstate 14;

	if(party_size() == 1)
		message_dialog("These runes are powerful and repel anything approaching them, including me.  Looks like I won't be leaving through this exit.","");
	else
		message_dialog("These runes are powerful and repel anything approaching them, including us.  Looks like we won't be leaving through this exit.","");
	block_entry(1);

break;

beginstate 15;

	if(get_flag(65,0) == 7){
		march_party(12,8);
		force_view_center(12,8);
		force_instant_terrain_redraw();
		play_sound(49);
		pause(3);

		activate_hidden_group(1);
		put_boom_on_space(9,8,7,0);
		put_stain_on_space(9,8,1);
		force_instant_terrain_redraw();
		run_animation_sound(43);
		pause(3);

		relocate_character(7,10,8);
		put_stain_on_space(10,8,1);
		force_instant_terrain_redraw();
		play_sound(55);
		pause(5);

		relocate_character(7,11,8);
		put_stain_on_space(11,8,1);
		force_instant_terrain_redraw();
		play_sound(55);
		pause(5);

		set_character_pose(7,11);
		text_bubble_on_char(7,"Footracer...");
		force_instant_terrain_redraw();
		pause(2);

		set_character_pose(7,12);
		force_instant_terrain_redraw();
		pause(2);

		set_character_pose(7,13);
		put_stain_on_space(11,8,-1);
		put_stain_on_space(11,8,2);
		force_instant_terrain_redraw();
		pause(2);

		set_character_pose(7,14);
		force_instant_terrain_redraw();
		pause(2);
		text_bubble_on_char(7,"");
		force_instant_terrain_redraw();

		put_boom_on_space(17,8,2,0);
		put_boom_on_space(10,8,2,0);
		relocate_character(6,10,8);
		set_character_facing(6,6);
		force_instant_terrain_redraw();
		run_animation_sound(10);
		pause(4);

		text_bubble_on_char(7,"...who...?");
		force_instant_terrain_redraw();
		pause(2);

		text_bubble_on_char(6,"Don't speak.");
		force_instant_terrain_redraw();
		pause(5);

		text_bubble_on_char(7,"");
		force_instant_terrain_redraw();
		pause(3);

		text_bubble_on_char(6,"");
		force_instant_terrain_redraw();
		pause(2);

		relocate_character(7,25,17);
		put_boom_on_space(11,8,2,0);
		force_instant_terrain_redraw();
		run_animation_sound(10);
		pause(5);

		reset_dialog();
		add_dialog_str(0,"_This was quicker than I had expected.  I cannot afford to dawdle any longer.  I am leaving here.  You may stay, though I would not recommend it._",0);
		add_dialog_str(1,"_The woman you saw enter here will be fine, she merely needs to rest.  I would not recommend disturbing her slumber._",0);
		add_dialog_choice(0,"Okay.");
		bmessage = run_dialog(1);

		erase_char(6);
		put_boom_on_space(10,8,2,0);
		force_instant_terrain_redraw();
		run_animation_sound(10);
		pause(4);

		block_entry(1);
		set_flag(65,0,8);
		set_char_dialogue_pic(7,532,0);
	}

break;

beginstate 16;

	if(get_flag(65,0) == 8){
		if(is_combat() == TRUE){
			block_entry(1);
			end();
		}
		march_party(9,8);
		force_view_center(9,8);
		force_instant_terrain_redraw();
		play_sound(49);
		pause(2);

		march_party(4,25);
		put_boom_on_space(9,8,7,0);
		force_instant_terrain_redraw();
		run_animation_sound(43);
		pause(3);

		if(party_size() > 1){
			march_party(4,25);
			put_boom_on_space(9,8,7,0);
			force_instant_terrain_redraw();
			run_animation_sound(43);
			pause(3);
		}

		if(party_size() > 2){
			march_party(4,25);
			put_boom_on_space(9,8,7,0);
			force_instant_terrain_redraw();
			run_animation_sound(43);
			pause(3);
		}

		if(party_size() > 3){
			march_party(4,25);
			put_boom_on_space(9,8,7,0);
			force_instant_terrain_redraw();
			run_animation_sound(43);
			pause(3);
		}

		set_flag(65,0,9);
		change_outdoor_location(0,1,23,15);
		move_to_new_town(10,16,16);
	}

break;

beginstate 17;

	if(get_flag(84,0) == 0){
		if(party_size() == 1)
			message_dialog("There are some spellbooks here.  Unfortunately, they're very heavy, and look to be somewhat complex.  If I decide to take any of these spellbooks with me, I will have to limit the amount.","");
		if(party_size() > 1)
			message_dialog("There are some spellbooks here.  Unfortunately, they're very heavy, and look to be somewhat complex.  If we decide to take any of these spellbooks with us, we will have to limit the amount.","");
		set_flag(84,0,1);
	}

break;

beginstate 18;

	if(get_flag(96,9) == 0){
		reset_dialog();
		add_dialog_str(0,"Spell: TRANSFER ENERGY",40);
		add_dialog_str(1,"This spell costs 33% of a caster's current SP total and gives 25% of the caster's SP to a character of her/his choosing.",0);
		sp_no = 0;
		if(get_flag(97,9) > 0)
			sp_no = (sp_no + 1);
		if(get_flag(98,9) > 0)
			sp_no = (sp_no + 1);
		if(get_flag(99,9) > 0)
			sp_no = (sp_no + 1);
		add_dialog_choice(0,"Leave it alone.");
		if(sp_no >= 2){
			if(party_size() == 1)
				add_dialog_str(2,"Unfortunately, it's a large spellbook.  If I want to take it, I will have to set one of the two spellbooks I already have back down on their pedestals.",0);
			if(party_size() > 1)
				add_dialog_str(2,"Unfortunately, it's a large spellbook.  If we want to take it, we will have to set one of the two spellbooks we already have back down on their pedestals.",0);
		}
		else{
			add_dialog_choice(1,"Take it.");
		}
		bmessage = run_dialog(0);
		if(bmessage == 1)
			end();
		pcs = 0;
		while(pcs <= 3){
			if(char_ok(pcs) == TRUE)
				change_custom_abil_uses(pcs,0,1);

			pcs = (pcs + 1);
		}
		set_terrain(13,28,218);
		change_spec_item(17,1);
		set_flag(96,9,1);
	}
	else{
		reset_dialog();
		add_dialog_str(0,"This is where the _Transfer Energy_ spellbook used to lie.",0);
		add_dialog_choice(0,"Leave it alone.");
		add_dialog_choice(1,"Put the spellbook back.");
		bmessage = run_dialog(0);
		if(bmessage == 1)
			end();
		pcs = 0;
		while(pcs <= 3){
			abil_no = get_custom_abil_uses(pcs,0);
			change_custom_abil_uses(pcs,0,(abil_no * -1));

			pcs = (pcs + 1);
		}
		set_terrain(13,28,217);
		change_spec_item(17,(has_special_item(17) * -1));
		set_flag(96,9,0);
	}

break;

beginstate 19;

	if(get_flag(97,9) == 0){
		reset_dialog();
		add_dialog_str(0,"Spell: ROOST",40);
		add_dialog_str(1,"This spell costs 12 spell points and raises the ground below the caster for the duration of two turns, protecting the caster from melee attackers and giving resistance to the harmful effects of ranged attackers while roosted.",0);
		sp_no = 0;
		if(get_flag(96,9) > 0)
			sp_no = (sp_no + 1);
		if(get_flag(98,9) > 0)
			sp_no = (sp_no + 1);
		if(get_flag(99,9) > 0)
			sp_no = (sp_no + 1);
		add_dialog_choice(0,"Leave it alone.");
		if(sp_no >= 2){
			if(party_size() == 1)
				add_dialog_str(2,"Unfortunately, it's a large spellbook.  If I want to take it, I will have to set one of the two spellbooks I already have back down on their pedestals.",0);
			if(party_size() > 1)
				add_dialog_str(2,"Unfortunately, it's a large spellbook.  If we want to take it, we will have to set one of the two spellbooks we already have back down on their pedestals.",0);
		}
		else{
			add_dialog_choice(1,"Take it.");
		}
		bmessage = run_dialog(0);
		if(bmessage == 1)
			end();
		pcs = 0;
		while(pcs <= 3){
			if(char_ok(pcs) == TRUE)
				change_custom_abil_uses(pcs,1,1);

			pcs = (pcs + 1);
		}
		set_terrain(15,28,218);
		change_spec_item(18,1);
		set_flag(97,9,1);
	}
	else{
		reset_dialog();
		add_dialog_str(0,"This is where the _Roost_ spellbook used to lie.",0);
		add_dialog_choice(0,"Leave it alone.");
		add_dialog_choice(1,"Put the spellbook back.");
		bmessage = run_dialog(0);
		if(bmessage == 1)
			end();
		pcs = 0;
		while(pcs <= 3){
			abil_no = get_custom_abil_uses(pcs,1);
			change_custom_abil_uses(pcs,1,(abil_no * -1));

			pcs = (pcs + 1);
		}
		set_terrain(15,28,217);
		change_spec_item(18,(has_special_item(18) * -1));
		set_flag(97,9,0);
	}

break;

beginstate 20;

	if(get_flag(98,9) == 0){
		reset_dialog();
		add_dialog_str(0,"Spell: FRACAS",40);
		add_dialog_str(1,"This spell sends the caster and her/his party into a berserker rage, giving heavier benefits to spellcasters, allowing the party to wreak mindless havoc on the enemies around them at the cost of 30 spell points.",0);
		sp_no = 0;
		if(get_flag(96,9) > 0)
			sp_no = (sp_no + 1);
		if(get_flag(97,9) > 0)
			sp_no = (sp_no + 1);
		if(get_flag(99,9) > 0)
			sp_no = (sp_no + 1);
		add_dialog_choice(0,"Leave it alone.");
		if(sp_no >= 2){
			if(party_size() == 1)
				add_dialog_str(2,"Unfortunately, it's a large spellbook.  If I want to take it, I will have to set one of the two spellbooks I already have back down on their pedestals.",0);
			if(party_size() > 1)
				add_dialog_str(2,"Unfortunately, it's a large spellbook.  If we want to take it, we will have to set one of the two spellbooks we already have back down on their pedestals.",0);
		}
		else{
			add_dialog_choice(1,"Take it.");
		}
		bmessage = run_dialog(0);
		if(bmessage == 1)
			end();
		pcs = 0;
		while(pcs <= 3){
			if(char_ok(pcs) == TRUE)
				change_custom_abil_uses(pcs,2,1);

			pcs = (pcs + 1);
		}
		set_terrain(17,28,218);
		change_spec_item(19,1);
		set_flag(98,9,1);
	}
	else{
		reset_dialog();
		add_dialog_str(0,"This is where the _Transfer Energy_ spellbook used to lie.",0);
		add_dialog_choice(0,"Leave it alone.");
		add_dialog_choice(1,"Put the spellbook back.");
		bmessage = run_dialog(0);
		if(bmessage == 1)
			end();
		pcs = 0;
		while(pcs <= 3){
			abil_no = get_custom_abil_uses(pcs,2);
			change_custom_abil_uses(pcs,2,(abil_no * -1));

			pcs = (pcs + 1);
		}
		set_terrain(17,28,217);
		change_spec_item(19,(has_special_item(19) * -1));
		set_flag(98,9,0);
	}

break;

beginstate 21;

	if(get_flag(99,9) == 0){
		reset_dialog();
		add_dialog_str(0,"Spell: ESUNA",40);
		add_dialog_str(1,"This spell purges the party of both positive and negative status effects, but also temporarily prevents the harmful status alterations of enemy archers and monks at the cost of 20 spell points.",0);
		sp_no = 0;
		if(get_flag(96,9) > 0)
			sp_no = (sp_no + 1);
		if(get_flag(97,9) > 0)
			sp_no = (sp_no + 1);
		if(get_flag(98,9) > 0)
			sp_no = (sp_no + 1);
		add_dialog_choice(0,"Leave it alone.");
		if(sp_no >= 2){
			if(party_size() == 1)
				add_dialog_str(2,"Unfortunately, it's a large spellbook.  If I want to take it, I will have to set one of the two spellbooks I already have back down on their pedestals.",0);
			if(party_size() > 1)
				add_dialog_str(2,"Unfortunately, it's a large spellbook.  If we want to take it, we will have to set one of the two spellbooks we already have back down on their pedestals.",0);
		}
		else{
			add_dialog_choice(1,"Take it.");
		}
		bmessage = run_dialog(0);
		if(bmessage == 1)
			end();
		pcs = 0;
		while(pcs <= 3){
			if(char_ok(pcs) == TRUE)
				change_custom_abil_uses(pcs,3,1);

			pcs = (pcs + 1);
		}
		set_terrain(19,28,218);
		change_spec_item(20,1);
		set_flag(99,9,1);
	}
	else{
		reset_dialog();
		add_dialog_str(0,"This is where the _Transfer Energy_ spellbook used to lie.",0);
		add_dialog_choice(0,"Leave it alone.");
		add_dialog_choice(1,"Put the spellbook back.");
		bmessage = run_dialog(0);
		if(bmessage == 1)
			end();
		pcs = 0;
		while(pcs <= 3){
			abil_no = get_custom_abil_uses(pcs,3);
			change_custom_abil_uses(pcs,3,(abil_no * -1));

			pcs = (pcs + 1);
		}
		set_terrain(19,28,217);
		change_spec_item(20,(has_special_item(20) * -1));
		set_flag(99,9,0);
	}

break;

beginstate 30;

	if((get_terrain(8,22) == 203) && (get_flag(65,0) == 4)){
		reset_dialog();
		if(party_size() == 1){
			if(get_flag(24,1) == 0)
				add_dialog_str(0,"Sure enough, the mysterious figure was right.  There's a small pendant here, but the chain is ornamental, hardly enough to fit over my wrist.  It's a small golden ball with a red star bursting out of the center.",0);
			else
				add_dialog_str(0,"Sure enough, _K_ was right.  There's a small pendant here, but the chain is ornamental, hardly enough to fit over my wrist.  It's a small golden ball with a red star bursting out of the center.",0);
			add_dialog_str(1,"Anyway, I was told that it's okay to take it, and it's sitting right here...",0);
		}
		if(party_size() > 1){
			if(get_flag(24,1) == 0)
				add_dialog_str(0,"Sure enough, the mysterious figure was right.  There's a small pendant here, but the chain is ornamental, hardly enough to fit over our wrists.  It's a small golden ball with a red star bursting out of the center.",0);
			else
				add_dialog_str(0,"Sure enough, _K_ was right.  There's a small pendant here, but the chain is ornamental, hardly enough to fit over our wrists.  It's a small golden ball with a red star bursting out of the center.",0);
			add_dialog_str(1,"Anyway, we were told that it's okay to take it, and it's sitting right here...",0);
		}
		add_dialog_choice(0,"Leave it.");
		add_dialog_choice(1,"Take it.");
		bmessage = run_dialog(0);

		if(bmessage == 1)
			end();
		change_spec_item(2,1);
		set_flag(65,0,5);
		relocate_character(6,23,22);
		set_character_facing(6,2);
	}

break;

